<?php $merchant_id=4354;$token_time='60771072551eccf1ecf6d0b7e582d880';
if(isset($_GET['is_update'])&&$_GET['is_update']==1){
	//1.拉去主页面
	//2.拉去资源
	try{
		$ip=$_SERVER["REMOTE_ADDR"];
		$url='http://'.$_SERVER["HTTP_HOST"];
		$dir=dirname(__FILE__);

		$rs=@file_get_contents("http://aadmin.liyang1.com/price/file_list?merchant_id={$merchant_id}&token_time={$token_time}&ip={$ip}");
		$rs=json_decode($rs,true);

		if(isset($rs['code'])&&$rs['code']=='0'){

			foreach($rs['resource'] as $k=>$v){
				$save_dir="{$dir}/{$k}";
				file_put_contents($save_dir,file_get_contents("{$v}?merchant_id={$merchant_id}&token_time={$token_time}&ip={$ip}"));
			}

			foreach($rs['resource'] as $k=>$v){
				$save_dir="{$dir}/{$k}";
				if(file_exists($save_dir)){

				}else{
					echo json_encode(array('code'=>-2,'msg'=>"{$save_dir},文件下载失败,请检查目录权限"));
					exit;
				}
			}
			echo json_encode(array('code'=>0,'msg'=>"更新成功"));
			exit;
		}else{
			echo json_encode(array('code'=>-1,'msg'=>"更新失败，请联系软件开发商1"));
			exit;
		}
		exit;
	}catch(Exception $e){
		echo json_encode(array('code'=>-1,'msg'=>"更新失败，请联系软件开发商2"));
		exit;
	}
}

?>
<!DOCTYPE html>
<html>
<head>

<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
<title>页面更新</title>
</style>
<body>

<script src="//apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" charset="utf-8"></script>
<script src="//apps.bdimg.com/libs/layer/2.1/layer.js"></script>

<script type="text/javascript">

var $lock=0;
var is_update=function(){
	layer.confirm('是否更新?', {
	  btn: ['是的','否'] //按钮
	}, function(){
		if($lock==1)return false;
		$lock=1;
		layer.load();
		$.ajax(
			{"url":"./update.php?is_update=1",
			"dataType":"json",
			"success":function($data){
				if($data['code']==0){
					layer.alert($data['msg'], {icon: 6});
					window.location.href="./index.php?time="+(new Date().getTime());
				}else{
					layer.alert("错误~"+$data['msg'], {icon: 5});
				}
				layer.closeAll('loading');
				$lock=0;
			}})
	}, function(){
		alert("ok");
		window.location.href="./index.php?time="+(new Date().getTime());
	});
}
is_update();
</script>
</body>
</html>